package com.zt.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zt.domain.Oneuser;
import com.zt.mapper.OneuserMapper;
import com.zt.service.OneuserService;
import com.zt.utils.JwtToken;
import com.zt.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Api(value = "测试")
public class OController {

    @Resource
    private OneuserService oneuserService;
    @Resource
    private OneuserMapper oneuserMapper;

//    @PostMapping("/login")
//    public Result login(@RequestBody Oneuser oneuser) {
//        Oneuser oneuser1 = oneuserMapper.selectOne(new LambdaQueryWrapper<Oneuser>().eq(Oneuser::getUsername, 123).eq(Oneuser::getPassword, 123));
//
//        Map<String, Object> map = new HashMap<>();
//        map.put("username", oneuser1.getUsername());
//        map.put("password", oneuser1.getPassword());
//        String token = JwtToken.createJetToken(map);
//        return Result.success(token);
//    }


    /**
     * 查询
     */

    @PostMapping("/list")
    @ApiOperation("list")
    public Result list() {
        List<Oneuser> list = oneuserService.list();
        return Result.success(list);
    }

    /**
     * 添加
     */

    @PostMapping("/add")
    @ApiOperation("add")
    public Result add(@RequestBody Oneuser oneuser) {
        oneuserService.save(oneuser);
        return Result.success("添加成功");
    }

    /**
     * 删除
     */

    @PostMapping("/delete")
    @ApiOperation("delete")
    public Result delete(@RequestParam Integer id) {
        oneuserService.removeById(id);
        return Result.success("删除成功");
    }

    /**
     * 修改
     */

    @PostMapping("/update")
    @ApiOperation("update")

    public Result update(@RequestBody Oneuser oneuser) {
        oneuserService.updateById(oneuser);
        return Result.success("修改成功");
    }

    /**
     * 根据用户进行的查询
     */

    @PostMapping("/ById")
    @ApiOperation("ById")
    public Result ById(@RequestParam Integer id) {
        Oneuser byId = oneuserService.getById(id);
        return Result.success(byId);
    }

}
